﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class GoroSort
    {
        public GoroSort()
        {
            int testCount = Int32.Parse(TestConsole.ReadLine());

            for (int testCase = 1; testCase <= testCount; testCase++)
            {
                int count = Int32.Parse(TestConsole.ReadLine());
                int[] array = new int[count + 1];
                string[] input = TestConsole.ReadLine().Split(' ');
                for (int i = 0; i < count; i++)
                {
                    array[i + 1] = Int32.Parse(input[i]);
                }
                int match = 0;
                int notmatch = 0;
                for (int i = 1; i <= count; i++)
                {
                    int value = array[i];
                    if (value == i)
                    {
                    }
                    else if (array[value] == i)
                    {
                        match++;
                    }
                    else
                    {
                        notmatch++;
                    }
                }
                //int result = match + (notmatch > 0 ? (notmatch - 1) * 2 : 0);
                int result = match + notmatch;
                Console.WriteLine(string.Format("Case #{0}: {1}.000000", testCase, result));
            }
        }
    }
}
